import execjs
import requests


def get_pwd(password):
    with open("13微信公众号JS代码.js", encoding="utf-8") as f:
        jscode = f.read()
        resp = execjs.compile(jscode).call("getpwd", password)
        return resp


def login_wx():
    url = "https://mp.weixin.qq.com/"

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                      "Chrome/89.0.4389.82 Safari/537.36 ",
        "sec-ch-ua": '"Google Chrome";v = "89", "Chromium";v = "89", ";Not A Brand";v = "99"',
        "sec-ch-ua-mobile": "?0",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
    }

    form_data = {
        "username": login,
        "pwd": pwd,
        "imgcode": "",
        "f": "json",
        "userlang": "zh_CN",
        "redirect_url": "",
        "token": "",
        "lang": "zh_CN",
        "ajax": 1,
    }
    response = requests.post(url=url, headers=headers, data=form_data)
    return response


if __name__ == '__main__':
    login = input("请输入账号：")
    password = input("请输入密码：")
    pwd = get_pwd(password)
    response = login_wx()
    print(response.text)
